package com.ruoyi.web.controller.safe;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.RiskUnit;
import com.ruoyi.safe.service.IRiskUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风险单元Controller
 * 
 * @author yxf
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/safe/unit")
public class RiskUnitController extends BaseController
{
    @Autowired
    private IRiskUnitService riskUnitService;

    /**
     * 查询风险单元列表
     */
    @PreAuthorize("@ss.hasPermi('safe:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskUnit riskUnit)
    {
        startPage();
        List<RiskUnit> list = riskUnitService.selectRiskUnitList(riskUnit);
        return getDataTable(list);
    }

    /**
     * 导出风险单元列表
     */
    @PreAuthorize("@ss.hasPermi('safe:unit:export')")
    @Log(title = "风险单元", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RiskUnit riskUnit)
    {
        List<RiskUnit> list = riskUnitService.selectRiskUnitList(riskUnit);
        ExcelUtil<RiskUnit> util = new ExcelUtil<RiskUnit>(RiskUnit.class);
        return util.exportExcel(list, "风险单元数据");
    }

    /**
     * 获取风险单元详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:unit:query')")
    @GetMapping(value = "/{ruId}")
    public AjaxResult getInfo(@PathVariable("ruId") Long ruId)
    {
        return AjaxResult.success(riskUnitService.selectRiskUnitById(ruId));
    }

    /**
     * 新增风险单元
     */
    @PreAuthorize("@ss.hasPermi('safe:unit:add')")
    @Log(title = "风险单元", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskUnit riskUnit)
    {
        return toAjax(riskUnitService.insertRiskUnit(riskUnit));
    }

    /**
     * 修改风险单元
     */
    @PreAuthorize("@ss.hasPermi('safe:unit:edit')")
    @Log(title = "风险单元", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskUnit riskUnit)
    {
        return toAjax(riskUnitService.updateRiskUnit(riskUnit));
    }

    /**
     * 删除风险单元
     */
    @PreAuthorize("@ss.hasPermi('safe:unit:remove')")
    @Log(title = "风险单元", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruIds}")
    public AjaxResult remove(@PathVariable Long[] ruIds)
    {
        return toAjax(riskUnitService.deleteRiskUnitByIds(ruIds));
    }
}
